package com.njtech.smartuniversity.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.njtech.smartuniversity.bean.CaseobjBean;
import com.njtech.smartuniversity.bean.CaseobjBeanExample;
import com.njtech.smartuniversity.dao.CaseobjBeanMapper;
import com.njtech.smartuniversity.service.CaseobjService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by ritchie on 6/25/18
 */

@Service
public class CaseobjServiceImpl implements CaseobjService {

    @Autowired
    public CaseobjBeanMapper mCaseobjBeanMapper;

    @Override
    public CaseobjBean select(int id) {

        return  mCaseobjBeanMapper.select(id);
    }

    @Override
    public int update(CaseobjBean areaBean) {
        Integer id = areaBean.getId();
        return  mCaseobjBeanMapper.update(areaBean);
    }

    @Override
    public List<CaseobjBean> getAllCaseobj(int area_id) {
        CaseobjBeanExample caseBeanExample = new CaseobjBeanExample();
        CaseobjBeanExample.Criteria criteria =caseBeanExample.createCriteria() ;
        criteria.andGNameEqualTo(area_id);
        return mCaseobjBeanMapper.selectByExample(caseBeanExample);
    }

    @Override
    public PageInfo<CaseobjBean> getCasesByPage(int pageNum, int pageSize,int area_id) {
        PageHelper.startPage(pageNum, pageSize);
        List<CaseobjBean> list = getAllCaseobj(area_id);//这个查询会分页
        return new PageInfo<>(list);
    }


    @Override
    public boolean deleteById(int id) {
        int result = mCaseobjBeanMapper.delete(id);
        return result != 0;
    }

    @Override
    public int addCaseobj(CaseobjBean caseBean) {
        return mCaseobjBeanMapper.insert(caseBean);
    }




}
